package com.xxxx.yygh.common.exception.handler;

import com.xxxx.yygh.common.exception.YyghException;
import com.xxxx.yygh.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Lee.s
 * @description 全局异常处理类
 * @date 2021/03/11 12:38
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(YyghException.class)
    @ResponseBody
    public Result error(YyghException e) {
        log.error(e.getMessage());
        return Result.build(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        log.error(e.getMessage());
        return Result.fail();
    }
}
